package com.timmy.google_play.factory;

import com.timmy.google_play.base.BaseFragment;
import com.timmy.google_play.fragment.AppFragment;
import com.timmy.google_play.fragment.CategoryFragment;
import com.timmy.google_play.fragment.GameFragment;
import com.timmy.google_play.fragment.HomeFragment;
import com.timmy.google_play.fragment.HotFragment;
import com.timmy.google_play.fragment.RecommendFragment;
import com.timmy.google_play.fragment.SubjectFramgent;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Timmy on 2016/12/7.
 */
public class FragmentFactory {

    public static final int FRAGMENT_HOME      = 0;//首页
    public static final int FRAGMENT_APP       = 1;//应用
    public static final int FRAGMENT_GAME      = 2;//游戏
    public static final int FRAGMENT_SUBJECT   = 3;//专题
    public static final int FRAGMENT_RECOMMEND = 4;//推荐
    public static final int FRAGMENT_CATEGORY  = 5;//分类
    public static final int FRAGMENT_HOT       = 6;//排行

    public static Map<Integer,BaseFragment> map = new HashMap<>();

    public static BaseFragment createFragment(int position) {


        BaseFragment fragment = null;

        if (map.containsKey(position)) {

            return map.get(position);
        }

        switch (position) {

            case FRAGMENT_HOME:
                fragment = new HomeFragment();
                break;
            case FRAGMENT_APP:
                fragment = new AppFragment();
                break;
            case FRAGMENT_GAME:
                fragment = new GameFragment();
                break;
            case FRAGMENT_SUBJECT:
                fragment = new SubjectFramgent();
                break;
            case FRAGMENT_RECOMMEND:
                fragment = new RecommendFragment();
                break;
            case FRAGMENT_CATEGORY:
                fragment = new CategoryFragment();
                break;
            case FRAGMENT_HOT:
                fragment = new HotFragment();
                break;
        }

        map.put(position,fragment);


        return fragment;
    }
}
